package com.intellagric.controller.agritech.controller;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.common.utils.JsonUtils;
import com.intellagric.module.agritech.AgtUserTagVo;
import com.intellagric.pojo.AgtUserTag;
import com.intellagric.service.agritech.UserTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Author: cwq
 * @Date: 2019/2/26 10:45
 * @Description:
 */
@RequestMapping("/api/agt_user_tag")
@Controller
public class UserTagController {

    @Autowired
    private UserTagService userTagService;

    @RequestMapping("/add")
    @ResponseBody
    public ResponseMessage add(AgtUserTag userTag) {
        return userTagService.addUserTag(userTag);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return userTagService.deleteUserTag(id);
    }

    @RequestMapping("/edit")
    @ResponseBody
    public ResponseMessage edit(AgtUserTag userTag) {
        return userTagService.editUserTag(userTag);
    }

    @RequestMapping("/{id}")
    @ResponseBody
    public AgtUserTag get(@PathVariable String id) {
        return userTagService.getUserTagById(id);
    }

    @RequestMapping("/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return userTagService.getUserTagList();
    }

    @RequestMapping("/query")
    @ResponseBody
    public LayuiDataGridResult getListByVo(AgtUserTagVo agtUserTagVo, int page, int limit) {
        return userTagService.getUserTagListByVo(agtUserTagVo, page, limit);
    }

    @RequestMapping("/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return userTagService.getUserTagByPage(page, limit);
    }

    //TODO 待修改
    @RequestMapping("/test")
    @ResponseBody
    public List<AgtUserTag> getUserTagSumWeightByUserId(AgtUserTagVo agtUserTagVo) {
        List<AgtUserTag> agtUserTagList = userTagService.getUserTagSumWeightByVo(agtUserTagVo);
        String str = JsonUtils.objectToJson(agtUserTagList).replaceAll("tagName", "name").replaceAll("weight", "value");
        System.out.println(str);
        return agtUserTagList;
    }

    //TODO 待修改
    @RequestMapping("/test1")
    @ResponseBody
    public Map getUserTagSumActionCountGroupByActionIdByUserId(AgtUserTagVo agtUserTagVo) {
        Map agtUserTagList = userTagService.getUserTagSumActionCountGroupByActionIdByVo(agtUserTagVo);
        System.out.println(((List) agtUserTagList.get("legendData")).get(0));
        return agtUserTagList;
    }
}
